
import { defineStore } from "pinia";
import channelApi from '@/api/index'
import type { banner, items, categorys } from '@/api/index'

interface useChannelStoreData {
  bannerList: banner[]
  categoryList: any
  cateNameList: categorys[] | undefined
}

export const useChannelStore = defineStore('channel', {
  state(): useChannelStoreData {
    return {
      bannerList: [],
      categoryList: {
        category: [],
        itemIdList: [],
        itemList: []
      },
      cateNameList: []
    }
  },
  actions: {
    async getChannel(id: number) {
      try {
        const res = await channelApi.getChannel(id)
        // console.log(res);
        this.bannerList = res.currentCategory.bannerList
        this.categoryList = res.categoryItemList
        this.cateNameList = res.categoryList
      } catch (error) {
        console.log(error);

      }
    }
  },
  getters: {
    swiperList(state) {
      return state.categoryList
    }

  }
})

